package com.hexiang.handler;

import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
import lombok.extern.slf4j.Slf4j;

/**
 * sentinel限流或降级处理类
 *
 */
@Slf4j
public class HelloBlockHandler  {


    private HelloBlockHandler() {
    }

    /**
     * 降级处理
     *
     * @param ex      BlockException
     * @return CommonResponse
     */
    public static String sayHello(BlockException ex) {
        if (ex instanceof FlowException) {
            log.warn("overhead");
            return "overhead";
        } else {
            log.warn("degrad");
            return "degrad";
        }
    }
    public static String err(BlockException ex) {
        if (ex instanceof FlowException) {
            log.warn("overhead");
            return "overhead";
        } else {
            log.warn("degrad");
            return "degrad";
        }
    }
}
